package com.wyz.activemq.queue;


import com.wyz.activemq.config.AppConfig;
import com.wyz.activemq.utils.ActiveConnectionUtil;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * @Author: wyz
 * @Date: 2019/4/12 22:02
 * @Description: 这是activeMQ 队列模式之消费者
 */
public class Consumer {

    public static void main(String[] args) throws JMSException {
        MessageConsumer consumer = ActiveConnectionUtil.getConsumer(AppConfig.ACTIVEMQ_URL, AppConfig.QUEUE_NAME, Session.AUTO_ACKNOWLEDGE);
        //这是消息监听
        consumer.setMessageListener(new MessageListener() {
            public void onMessage(Message message) {
                TextMessage textMessage = (TextMessage) message;
                try {
                    //获取对列中的消息
                    String text = textMessage.getText();
                    System.out.println("消费者消费消息==="+text);
                } catch (JMSException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
